package com.itheima.test3;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/*
上传文件的 服务端
 */
public class FuwuClient {

    public static void main(String[] args) throws IOException {
        //创建服务端对象
        ServerSocket ss = new ServerSocket(8888);
        // 等待建立连接 获取socket对象
        Socket socket = ss.accept();
        //获取输入流
        InputStream is = socket.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);
        // 创建本地输出流
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("day16\\copy\\meinv.jpg"));
        //读写
               //读写
        int b;
        while ((b = bis.read()) != -1) {
            bos.write(b);
        }

        //向客户端回写数据
        OutputStream os = socket.getOutputStream();
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os));
        writer.write("上传成功");
        writer.newLine();
        writer.flush();
        socket.shutdownOutput();
        //释放资源
        bos.close();
        ss.close();


    }
}
